package main

import (
	"fmt"
	"log"
	"net"
)

func main() {
	socket, err := net.ListenUDP("udp4", &net.UDPAddr{
		IP:   net.IPv4(192, 168, 20, 138),
		Port: 3200,
	})
	if err != nil {
		fmt.Println(err)
		return
	}
	defer socket.Close()
	for {
		// 读取数据
		data := make([]byte, 100)
		read, remoteAddr, err := socket.ReadFromUDP(data)
		if err != nil {
			fmt.Println("读取数据失败!", err)
			continue
		}
		log.Println(read, remoteAddr)
		fmt.Printf("%s\n", string(data))
	}
}
